package com.wj.crm.controller;

import com.wj.crm.base.BaseController;
import com.wj.crm.base.ResultInfo;
import com.wj.crm.query.CustomerLossQuery;
import com.wj.crm.query.CustomerOrderQuery;
import com.wj.crm.service.CustomerLossService;
import com.wj.crm.vo.CustomerLoss;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @author WangJin
 * @version 1.0
 * @date 2022/1/25 13:34
 */
@Controller
@RequestMapping("customer_loss")
public class CustomerLossController extends BaseController {

    @Autowired
    private CustomerLossService customerLossService;

    @RequestMapping("index")
    public String toCustomerLossPage(){

        return "customerLoss/customer_loss";
    }

    /**
     * 分页多条件查询客户流失列表
     * @param
     * @return java.util.Map<java.lang.String,java.lang.Object>
     */
    @RequestMapping("list")
    @ResponseBody
    public Map<String,Object> queryCustomerLossByParams(CustomerLossQuery customerLossQuery) {
        return customerLossService.queryCustomerLossByParams(customerLossQuery);
    }

    /**
     * 打开添加暂缓/详情页面
     * @param lossId
     * @param model
     * @return
     */
    @RequestMapping("toCustomerLossPage")
    public String toCustomerRepPage(Integer lossId, Model model){  //客户暂缓页面
    // 通过流失客户的ID查询对应流失客户的记录
        CustomerLoss customerLoss = customerLossService.selectByPrimaryKey(lossId);
        // 将流失客户对应的数据存到请求域中
        model.addAttribute("customerLoss", customerLoss);

        return "customerLoss/customer_rep";
    }

    /**
     * 更新流失客户的流失状态
     * @param
     * @return com.wj.crm.base.ResultInfo
     */
    @PostMapping("updateCustomerLossStateById")
    @ResponseBody
    public ResultInfo updateCustomerLossStateById(Integer id, String lossReason) {
        customerLossService.updateCustomerLossStateById(id, lossReason);
        return success("确认流失成功！");
    }

    /**
     * 更新流失客户的流失状态 取消流失
     * @param
     * @return com.wj.crm.base.ResultInfo
     */
    @PostMapping("updateCustomerLossStateById02")
    @ResponseBody
    public ResultInfo updateCustomerLossStateById02(Integer id, String lossReason) {
        customerLossService.updateCustomerLossStateById02(id, lossReason);
        return success("取消流失成功！");
    }

}
